package com.brainardphotography.blog.service;

import java.io.Serializable;

import com.brainardphotography.blog.BlogUser;
import com.brainardphotography.blog.dao.BlogUserDAO;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.google.inject.servlet.SessionScoped;

@SessionScoped
public class AuthService implements Serializable {
	private static final long serialVersionUID = -8280743581972879929L;

	private BlogUser user = null;

	public AuthService() {

	}

	public BlogUser getBlogUser() {
		UserService users = UserServiceFactory.getUserService();

		if (users.isUserLoggedIn() && this.user == null) {
			BlogUserDAO dao = new BlogUserDAO();

			this.user = dao.get(users.getCurrentUser());
		}

		return this.user;
	}
}
